import QtQuick 2.2
import QtQuick.Window 2.1

Window {
    visible: true;
    width: 1400;
    height: 900;

    Rectangle {
        id: p;
        anchors.fill: parent;

        Text {
            id: t;
            anchors.centerIn: parent;
            text: "Hello QtQuick";
            font {
                weight: Font.Light;
                family: "微软雅黑";
                pointSize: 30;
            }
        }

        Loader {
            id: redPicker;
            source: "ColorPicker.qml";
            anchors.left: parent.left;
            anchors.leftMargin: 7;
            anchors.bottom: parent.bottom;
            anchors.bottomMargin: 7;
            focus: true;

            onLoaded: {
                item.color = "pink";
                item.focus = true;
            }
        }

        Loader {
            id: bluePicker;
            source: "ColorPicker.qml";
            anchors.left: redPicker.right;
            anchors.leftMargin: 7;
            anchors.verticalCenter: redPicker.verticalCenter;
            focus: true;

            onLoaded: {
                item.color = "skyblue";
                item.focus = true;
            }
        }

        Connections {
            target: redPicker.item;
            onColorPicked: {
                t.color = clr;
                p.focusLog();
            }
        }

        Connections {
            target: bluePicker.item;
            onColorPicked: {
                t.color = clr;
                p.focusLog();
            }
        }

        Component.onCompleted: {
            console.log(redPicker.focus);
            console.log(redPicker.item.focus);
            console.log(bluePicker.focus);
            console.log(bluePicker.item.focus)
        }

        function focusLog(){
            console.log(redPicker.focus);
            console.log(redPicker.item.focus);
            console.log(bluePicker.focus);
            console.log(bluePicker.item.focus)
        }
    }

}
